package com.hdaccp.gymxmjpa.Controller;


import com.hdaccp.gymxmjpa.Dao.StaffDao;
import com.hdaccp.gymxmjpa.Service.StaffDaoImpl;
import com.hdaccp.gymxmjpa.entity.Coach;
import com.hdaccp.gymxmjpa.entity.Equipment;
import com.hdaccp.gymxmjpa.entity.Staff;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

@Controller
@RequestMapping("/staff")
public class StaffController {
    @Autowired
    private StaffDao staffDao1;
    @Autowired
    private StaffDaoImpl staffDao;
    @RequestMapping("/staff1")
    public String yemian(){

        return "WEB-INF/jsp/CStaff";
    }

    @RequestMapping("/query")
    @ResponseBody
    public Map<String,Object> query(String hyname, int pageSize, int pageNumber){
        Map<String,Object>  map1=new HashMap<String,Object>();
        map1.put("hyname",hyname);
        map1.put("qi",(pageNumber-1)*pageSize);
        map1.put("shi",pageSize);
        return staffDao.query(map1);
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Map<String,Object> del(int staffId){
        staffDao.del(staffId);
        return query("",5,1);
    }
    @RequestMapping("/insert")
    @ResponseBody
    public Map<String,Object> insert(Staff staff){
        System.out.println("进入controller！！！！");
        staffDao.insert(staff);
        return query("",5,1);
    }

    @RequestMapping("/cha")
    @ResponseBody
    public Optional<Staff> one(long staffId){
        return staffDao1.findById(staffId);
    }

    @RequestMapping("/update")
    @ResponseBody
    public Map<String,Object> update(Staff staff){
        System.out.println();
        staffDao.update(staff);
        return query("",5,1);
    }
}
